﻿using SalesSys.DAL.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace SalesSys.Site.Models
{
    /// <summary>
    /// 计划单模型类
    /// </summary>
    public class OrderDto
    {
        /// <summary>
        /// 编号
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 客户
        /// </summary>
        public Guid CustomerId { get; set; }

        /// <summary>
        /// 仓库
        /// </summary>
        public Guid ProviderId { get; set; }

        /// <summary>
        /// 关联锁价单编号
        /// </summary>
        public Guid LockOrderId { get; set; }

        /// <summary>
        /// 标件户头
        /// </summary>
        public Guid AccountId { get; set; }

        /// <summary>
        /// 地区
        /// </summary>
        public Guid DistrictId { get; set; }

        /// <summary>
        /// 详细地址
        /// </summary>
        [StringLength(100)]
        public string Address { get; set; }

        /// <summary>
        /// 付款方式-是否先款
        /// </summary>
        public bool IsFullPayment { get; set; }

        /// <summary>
        /// 是否锁价
        /// </summary>
        public bool IsLockPrice { get; set; }

        ///// <summary>
        ///// 是否标件
        ///// </summary>
        //public bool IsStandard { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 每吨运费
        /// </summary>
        public decimal DeliveryPrice { get; set; }

        /// <summary>
        /// 运费是否公户
        /// </summary>
        public bool IsPublicDelivery { get; set; }

        /// <summary>
        /// 是否送货：true=送货;false=自提
        /// </summary>
        public bool IsDelivery { get; set; }

        /// <summary>
        /// 联系人
        /// </summary>
        public string Contact { get; set; }

        /// <summary>
        /// 联系人手机号
        /// </summary>
        public string ContactPhone { get; set; }

        /// <summary>
        /// 车辆信息
        /// </summary>
        public string VehicleInfos { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remarks { get; set; }

        /// <summary>
        /// 供应商
        /// </summary>
        //public Guid SupplierId { get; set; }

        /// <summary>
        /// 货品信息
        /// </summary>
        
        //public string CommodityInfosJson { get; set; }
        /// <summary>
        /// 货品信息
        /// </summary>
        public virtual ICollection<CommodityInfoDto> CommodityInfos { get; set; }

        /// <summary>
        /// 直接优惠合计，优惠使用负值表示
        /// </summary>
        public decimal BargainingAmount { get; set; }

        /// <summary>
        /// 申请单价优惠金额,优惠使用负值表示
        /// </summary>
        public decimal ApplyDiscount { get; set; }

        ///// <summary>
        ///// 先款每吨优惠金额,根据先款计算出平均优惠单价
        ///// </summary>
        //public float UnitDiscount { get; set; }

        /// <summary>
        /// 订单类型
        /// </summary>
        public OrderType OrderType { get; set; }

        /// <summary>
        /// Dto转计划单实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public Order ToEntity(Order entity = null)
        {
            if (entity == null)
            {
                entity = new Order();
            }
            entity.Address = this.Address;
            entity.IsDelivery = this.IsDelivery;
            entity.IsFullPayment = this.IsFullPayment;
            entity.IsPublicDelivery = this.IsPublicDelivery;
            entity.IsLockPrice = this.IsLockPrice;
            //entity.IsStandard = this.IsStandard;
            entity.Remarks = this.Remarks;
            entity.DeliveryPrice = this.DeliveryPrice;
            // entity.UnitDiscount = this.UnitDiscount;
            entity.Contact = this.Contact;
            entity.ContactPhone = this.ContactPhone;
            entity.VehicleInfos = this.VehicleInfos;
            if (this.BargainingAmount != 0.0M)
                entity.BargainingAmount = this.BargainingAmount;
            if (this.ApplyDiscount != 0.0M)
                entity.ApplyDiscount = this.ApplyDiscount;
            entity.OrderType = this.OrderType;
            return entity;
        }
    }
}